package com.yami.shop.common.util;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;

/**
 * @author mac
 */
public class WechatHttpUtil {




    private  static  String appId = "wxe3e9b9ef57b6a3d6";
    private  static  String AppSecret = "71b7d687e0a14bb1c65ba11467411d5e";







    public static String getAccessToken(){
        String requestUrl="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+AppSecret;
        String s= HttpUtil.get(requestUrl);
        JSONObject jsonObject = new JSONObject(s);
        return jsonObject.getStr("access_token");
    }




    public  static String getOpenId(String code){
        String requestUrl="https://api.weixin.qq.com/sns/jscode2session?appid="+appId+"&secret="+AppSecret+"&js_code="+code+"&grant_type=authorization_code";
        String s= HttpUtil.get(requestUrl);
        JSONObject jsonObject = new JSONObject(s);
        return jsonObject.getStr("openid");
    }



}
